package Vista;

import Complementos.Validar;
import Complementos.Visual;
import Control.ControlFotoPaciente;
import Control.ControlPaciente;
import Control.ControlPersona;
import Control.ControlUbigeo;
import java.awt.Image;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileNameExtensionFilter;


/*
 * frmRegistrarPaciente.java
 *
 * Created on 01/08/2011, 11:35:35 AM. Programador : Diego Alvarado / Bruno
 * Alvarado Descripcion : Formulario de registro de paciente . Última
 * modificación : 22/08/2011 , 24.00 Observaciones : Falta validaciones ...
 * longitud de DNI,edad,tel,celular.
 *
 * Campos obligatorios: Todos validados, pero falta resolver el mensaje
 * predefinido que va a estar en txtAntecedentes.
 *
 * Modificaciones : * El campo DNI y celular ya están validados respecto a la
 * longitud. Se agregó en la clase Validar el método: validarLongitud(entero
 * longitud,cadena c); Modificaciones Bruno 19-8-2011 19:21: -edad se actualiza
 * con fecha de nacimiento ingresada, y se lo saco de campo obligatorio y
 * editable 20-8-2011 00.57 -Antecedentes es seleccionado cuando se clickea
 * 21-8-2011 15.20 -se paso a Validar
 * agregarCerosYNumeroAIncrementar(string,int) -cambie de lugar los botones
 * agregar y eliminar foto *Modificaciones Bruno 21/08 21.05 - se agrego icono
 * al programa y se parcho la ruta de las imagenes 22/8/ 24.00 - se agrego el
 * aspecto mac
 *
 *
 */
public class frmRegistrarPaciente extends javax.swing.JFrame {

    private ImageIcon etiquetaImagen;
    Validar validar = new Validar();
    // variable estatica y privada para el patron singlenton
    static private frmRegistrarPaciente objeto = null;
    /**
     * Creates new form frmRegistrarPaciente
     */
    String rutaOrigen = "";
    String fechaingreso;

    public frmRegistrarPaciente() {

        initComponents();
        this.setIconImage(new ImageIcon(getClass().getResource("/Media/logo1.png")).getImage());
        cargarCodigo();
        cargarComboDeptos();
        cargarFotoDefecto();
        valoresPorDefecto();

    }

//Patron Singlenton
    static public frmRegistrarPaciente getInstancia() {
        if (objeto == null) {
            objeto = new frmRegistrarPaciente();
        }
        return objeto;
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnGroupGenero = new javax.swing.ButtonGroup();
        btnGroupGrupo = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        lblCodPaciente = new javax.swing.JLabel();
        txtCodigoPaciente = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        txtNombres = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtApellidoPaterno = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        txtDni = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtDireccion = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txtTel = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        txtCelular = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        txtEmail = new javax.swing.JTextField();
        comboFecha = new datechooser.beans.DateChooserCombo();
        jLabel8 = new javax.swing.JLabel();
        txtEdad = new javax.swing.JTextField();
        btnRegistrar = new javax.swing.JButton();
        jLabel12 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtAntecedentes = new javax.swing.JTextArea();
        jLabel13 = new javax.swing.JLabel();
        txtRecomendado = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        lblFoto = new javax.swing.JLabel();
        btnAgregarFoto = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        rbtMasculino = new javax.swing.JRadioButton();
        rbtFemenino = new javax.swing.JRadioButton();
        jPanel4 = new javax.swing.JPanel();
        rbtAdulto = new javax.swing.JRadioButton();
        rbtNinho = new javax.swing.JRadioButton();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        btnEliminarFoto = new javax.swing.JButton();
        txtOcupacion = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        txtNacionalidad = new javax.swing.JTextField();
        jLabel24 = new javax.swing.JLabel();
        comboDepto = new javax.swing.JComboBox();
        comboProvincia = new javax.swing.JComboBox();
        jLabel15 = new javax.swing.JLabel();
        comboDistrito = new javax.swing.JComboBox();
        jLabel14 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        txtApellidoMaterno = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("..:: Consultorio Sonrisas :..    Registrar de paciente nuevo");
        setResizable(false);

        jPanel1.setBackground(new java.awt.Color(204, 204, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 153)), "Registrar paciente nuevo", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tunga", 0, 24), new java.awt.Color(255, 255, 153))); // NOI18N

        lblCodPaciente.setText("Código paciente:");

        txtCodigoPaciente.setEditable(false);

        jLabel1.setText("Nombres:");

        txtNombres.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
        txtNombres.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtNombresKeyPressed(evt);
            }
        });

        jLabel2.setText("Apellido Paterno:");

        txtApellidoPaterno.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtApellidoPaternoKeyPressed(evt);
            }
        });

        jLabel3.setText("DNI:");

        txtDni.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtDniKeyPressed(evt);
            }
        });

        jLabel4.setText("Dirección:");

        txtDireccion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtDireccionKeyPressed(evt);
            }
        });

        jLabel5.setText("Teléfono:");

        txtTel.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtTelKeyPressed(evt);
            }
        });

        jLabel6.setText("Celular:");

        txtCelular.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtCelularKeyPressed(evt);
            }
        });

        jLabel7.setText("Fecha Nac:");

        jLabel11.setText("Email:");

        txtEmail.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtEmailKeyPressed(evt);
            }
        });

        comboFecha.setCurrentView(new datechooser.view.appearance.AppearancesList("Grey",
            new datechooser.view.appearance.ViewAppearance("custom",
                new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11),
                    new java.awt.Color(0, 0, 0),
                    new java.awt.Color(0, 0, 255),
                    false,
                    true,
                    new datechooser.view.appearance.swing.ButtonPainter()),
                new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11),
                    new java.awt.Color(0, 0, 0),
                    new java.awt.Color(0, 0, 255),
                    true,
                    true,
                    new datechooser.view.appearance.swing.ButtonPainter()),
                new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11),
                    new java.awt.Color(0, 0, 255),
                    new java.awt.Color(0, 0, 255),
                    false,
                    true,
                    new datechooser.view.appearance.swing.ButtonPainter()),
                new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11),
                    new java.awt.Color(128, 128, 128),
                    new java.awt.Color(0, 0, 255),
                    false,
                    true,
                    new datechooser.view.appearance.swing.LabelPainter()),
                new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11),
                    new java.awt.Color(0, 0, 0),
                    new java.awt.Color(0, 0, 255),
                    false,
                    true,
                    new datechooser.view.appearance.swing.LabelPainter()),
                new datechooser.view.appearance.swing.SwingCellAppearance(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11),
                    new java.awt.Color(0, 0, 0),
                    new java.awt.Color(255, 0, 0),
                    false,
                    false,
                    new datechooser.view.appearance.swing.ButtonPainter()),
                (datechooser.view.BackRenderer)null,
                false,
                true)));
    comboFecha.setAutoScroll(false);
    comboFecha.setFormat(2);
    try {
        comboFecha.setDefaultPeriods(new datechooser.model.multiple.PeriodSet(new datechooser.model.multiple.Period(new java.util.GregorianCalendar(2012, 2, 17),
            new java.util.GregorianCalendar(2012, 2, 17))));
} catch (datechooser.model.exeptions.IncompatibleDataExeption e1) {
    e1.printStackTrace();
    }
    comboFecha.setLocale(new java.util.Locale("es", "PE", ""));
    comboFecha.setBehavior(datechooser.model.multiple.MultyModelBehavior.SELECT_SINGLE);
    comboFecha.addSelectionChangedListener(new datechooser.events.SelectionChangedListener() {
        public void onSelectionChange(datechooser.events.SelectionChangedEvent evt) {
            comboFechaOnSelectionChange(evt);
        }
    });

    jLabel8.setText("Edad:");

    txtEdad.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyPressed(java.awt.event.KeyEvent evt) {
            txtEdadKeyPressed(evt);
        }
    });

    btnRegistrar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Media/adduser1.png"))); // NOI18N
    btnRegistrar.setText("Registrar paciente");
    btnRegistrar.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            btnRegistrarActionPerformed(evt);
        }
    });

    jLabel12.setText("Antecedentes:");

    txtAntecedentes.setColumns(20);
    txtAntecedentes.setRows(5);
    txtAntecedentes.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            txtAntecedentesMouseClicked(evt);
        }
    });
    jScrollPane1.setViewportView(txtAntecedentes);

    jLabel13.setText("Recomendado por:");

    txtRecomendado.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyPressed(java.awt.event.KeyEvent evt) {
            txtRecomendadoKeyPressed(evt);
        }
    });

    jPanel2.setBackground(new java.awt.Color(204, 204, 255));
    jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 153)), "Foto"));

    lblFoto.setAutoscrolls(true);

    javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
    jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout.setHorizontalGroup(
        jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel2Layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(lblFoto, javax.swing.GroupLayout.DEFAULT_SIZE, 135, Short.MAX_VALUE)
            .addContainerGap())
    );
    jPanel2Layout.setVerticalGroup(
        jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel2Layout.createSequentialGroup()
            .addComponent(lblFoto, javax.swing.GroupLayout.DEFAULT_SIZE, 103, Short.MAX_VALUE)
            .addContainerGap())
    );

    btnAgregarFoto.setText("Agregar foto");
    btnAgregarFoto.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            btnAgregarFotoActionPerformed(evt);
        }
    });

    jPanel3.setBackground(new java.awt.Color(204, 204, 255));
    jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 204)), "Género"));

    rbtMasculino.setBackground(new java.awt.Color(204, 204, 255));
    btnGroupGenero.add(rbtMasculino);
    rbtMasculino.setText("Masculino");
    rbtMasculino.setActionCommand("M");

    rbtFemenino.setBackground(new java.awt.Color(204, 204, 255));
    btnGroupGenero.add(rbtFemenino);
    rbtFemenino.setText("Femenino");
    rbtFemenino.setActionCommand("F");

    javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
    jPanel3.setLayout(jPanel3Layout);
    jPanel3Layout.setHorizontalGroup(
        jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel3Layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(rbtMasculino)
            .addGap(18, 18, 18)
            .addComponent(rbtFemenino)
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );
    jPanel3Layout.setVerticalGroup(
        jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel3Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(rbtMasculino)
                .addComponent(rbtFemenino))
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );

    jPanel4.setBackground(new java.awt.Color(204, 204, 255));
    jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 153)), "Grupo"));

    rbtAdulto.setBackground(new java.awt.Color(204, 204, 255));
    btnGroupGrupo.add(rbtAdulto);
    rbtAdulto.setText("Adulto");

    rbtNinho.setBackground(new java.awt.Color(204, 204, 255));
    btnGroupGrupo.add(rbtNinho);
    rbtNinho.setText("Niño");

    javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
    jPanel4.setLayout(jPanel4Layout);
    jPanel4Layout.setHorizontalGroup(
        jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel4Layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(rbtAdulto)
            .addGap(32, 32, 32)
            .addComponent(rbtNinho)
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );
    jPanel4Layout.setVerticalGroup(
        jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel4Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(rbtAdulto)
                .addComponent(rbtNinho))
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );

    jLabel9.setForeground(new java.awt.Color(255, 0, 0));
    jLabel9.setText("*");

    jLabel10.setForeground(new java.awt.Color(255, 0, 0));
    jLabel10.setText("*");

    jLabel17.setForeground(new java.awt.Color(255, 0, 0));
    jLabel17.setText("(*) Campos obligatorios");

    btnEliminarFoto.setText("Eliminar foto");
    btnEliminarFoto.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            btnEliminarFotoActionPerformed(evt);
        }
    });

    txtOcupacion.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyPressed(java.awt.event.KeyEvent evt) {
            txtOcupacionKeyPressed(evt);
        }
    });

    jLabel18.setText("Ocupación:");

    jLabel19.setText("Departamento:");

    jLabel21.setText("Provincia:");

    jLabel22.setForeground(new java.awt.Color(255, 0, 0));
    jLabel22.setText("*");

    jLabel23.setForeground(new java.awt.Color(255, 0, 0));
    jLabel23.setText("*");

    txtNacionalidad.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyPressed(java.awt.event.KeyEvent evt) {
            txtNacionalidadKeyPressed(evt);
        }
    });

    jLabel24.setText("Nacionalidad:");

    comboDepto.addItemListener(new java.awt.event.ItemListener() {
        public void itemStateChanged(java.awt.event.ItemEvent evt) {
            comboDeptoItemStateChanged(evt);
        }
    });

    comboProvincia.addItemListener(new java.awt.event.ItemListener() {
        public void itemStateChanged(java.awt.event.ItemEvent evt) {
            comboProvinciaItemStateChanged(evt);
        }
    });

    jLabel15.setText("Distrito:");

    jLabel14.setForeground(new java.awt.Color(255, 51, 51));
    jLabel14.setText("*");

    jLabel16.setForeground(new java.awt.Color(255, 0, 51));
    jLabel16.setText("*");

    jLabel20.setText("Apellido Materno:");

    txtApellidoMaterno.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyPressed(java.awt.event.KeyEvent evt) {
            txtApellidoMaternoKeyPressed(evt);
        }
    });

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(22, 22, 22)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel3)
                        .addComponent(jLabel18)
                        .addComponent(jLabel24)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(lblCodPaciente)
                            .addComponent(jLabel20))
                        .addComponent(jLabel1))
                    .addGap(4, 4, 4))
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel11)
                                .addComponent(jLabel5)))
                        .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(txtNacionalidad, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 95, Short.MAX_VALUE)
                .addComponent(txtEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 95, Short.MAX_VALUE)
                .addComponent(txtCelular, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 95, Short.MAX_VALUE)
                .addComponent(txtTel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 95, Short.MAX_VALUE)
                .addComponent(txtDni, javax.swing.GroupLayout.DEFAULT_SIZE, 95, Short.MAX_VALUE)
                .addComponent(txtApellidoPaterno, javax.swing.GroupLayout.DEFAULT_SIZE, 95, Short.MAX_VALUE)
                .addComponent(txtDireccion, javax.swing.GroupLayout.DEFAULT_SIZE, 95, Short.MAX_VALUE)
                .addComponent(txtOcupacion, javax.swing.GroupLayout.DEFAULT_SIZE, 95, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addComponent(txtCodigoPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 0, Short.MAX_VALUE))
                .addComponent(txtApellidoMaterno)
                .addComponent(txtNombres))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                    .addComponent(jLabel10)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel21))
                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                    .addComponent(jLabel9)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel19))
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addComponent(jLabel16)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel7))
                .addComponent(jLabel8)
                .addComponent(jLabel13)
                .addComponent(jLabel12)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addComponent(jLabel14)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel15)))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(txtRecomendado, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(txtEdad, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(comboFecha, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(comboDistrito, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(comboProvincia, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(comboDepto, javax.swing.GroupLayout.Alignment.LEADING, 0, 115, Short.MAX_VALUE)))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jLabel23)))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(74, 74, 74)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(btnEliminarFoto, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnAgregarFoto, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 122, Short.MAX_VALUE)))
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addComponent(jLabel22)
                    .addGap(47, 47, 47)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnRegistrar, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel17, javax.swing.GroupLayout.Alignment.LEADING))))
            .addGap(78, 78, 78))
    );
    jPanel1Layout.setVerticalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(7, 7, 7)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txtCodigoPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lblCodPaciente))
                    .addGap(18, 18, 18)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel9)
                        .addComponent(jLabel19)
                        .addComponent(comboDepto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel2)
                        .addComponent(txtApellidoPaterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGap(10, 10, 10)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel21)
                                .addComponent(comboProvincia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(18, 18, 18)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel15)
                                .addComponent(comboDistrito, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGap(18, 18, 18)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel20)
                                .addComponent(txtApellidoMaterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel10))
                            .addGap(18, 18, 18)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel1)
                                .addComponent(txtNombres, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel14))))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGap(20, 20, 20)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel7)
                                    .addComponent(jLabel16)
                                    .addComponent(jLabel3)
                                    .addComponent(txtDni, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addComponent(comboFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel23))
                            .addGap(18, 18, 18)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel8)
                                .addComponent(txtEdad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel4)
                                .addComponent(txtDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(5, 5, 5)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(btnAgregarFoto)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(btnEliminarFoto)))
            .addGap(18, 18, 18)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel13)
                                .addComponent(txtRecomendado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(14, 14, 14))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel5)
                                .addComponent(txtTel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(18, 18, 18)))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGap(38, 38, 38)
                            .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(jLabel22)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel12)
                                        .addGap(0, 0, Short.MAX_VALUE))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(jLabel6)
                                            .addComponent(txtCelular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(18, 18, 18)))
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel11)
                                    .addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel18, javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(txtOcupacion, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)))))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                .addComponent(btnRegistrar)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel24)
                    .addComponent(txtNacionalidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
            .addGap(18, 18, 18)
            .addComponent(jLabel17)
            .addContainerGap(36, Short.MAX_VALUE))
    );

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addContainerGap())
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
            .addGap(0, 0, Short.MAX_VALUE)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
    );

    pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnAgregarFotoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregarFotoActionPerformed
        cambiarImagen();
    }//GEN-LAST:event_btnAgregarFotoActionPerformed

    private void btnRegistrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRegistrarActionPerformed
        if (camposObligatorios()) {
            char genero;
            char grupo;
            if (rbtMasculino.isSelected()) {
                genero = rbtMasculino.getActionCommand().charAt(0);
            } else {
                genero = rbtFemenino.getActionCommand().charAt(0);
            }

            if (rbtAdulto.isSelected()) {
                grupo = rbtAdulto.getActionCommand().charAt(0);
            } else {
                grupo = rbtNinho.getActionCommand().charAt(0);
            }

            ControlPaciente control = new ControlPaciente();
            ControlUbigeo controlUbi = new ControlUbigeo();


            int idubigeo = controlUbi.dameIdUbigeo(comboDepto.getSelectedIndex() + 1, comboProvincia.getSelectedIndex() + 1, comboDistrito.getSelectedIndex() + 1);

            String fecha = validar.cambiarFormatoFechaParaBD(comboFecha.getText());
            ControlPersona controlPersona = new ControlPersona();
            controlPersona.agregarPersona(txtNombres.getText(), txtApellidoPaterno.getText(), txtApellidoMaterno.getText(), txtDni.getText(), txtNacionalidad.getText(), txtDireccion.getText(), txtEmail.getText(), txtTel.getText(), txtCelular.getText(), fecha, genero, idubigeo);
            int codPersona = controlPersona.cargarCodigo();

            control.agregarPaciente(codPersona, Integer.parseInt(txtCodigoPaciente.getText()), txtAntecedentes.getText(), txtOcupacion.getText(), txtRecomendado.getText(), grupo, fechaingreso);
            ControlFotoPaciente controlFoto = new ControlFotoPaciente();
            
            if (!(rutaOrigen.equals("NoFoto"))) {
                controlFoto.agregarFoto(txtCodigoPaciente.getText(), rutaOrigen);
            }
                              
            JOptionPane.showMessageDialog(this, "Se ha registrado el paciente", "Registro completo", JOptionPane.INFORMATION_MESSAGE);
            int resp = JOptionPane.showConfirmDialog(this, "Desea registrar otro paciente?", "Registrar paciente", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);

            if (resp == 0) {
                limpiarVentana();
                cargarCodigo();
            } else {
                dispose();
            }
        }




    }//GEN-LAST:event_btnRegistrarActionPerformed

    private void txtNombresKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNombresKeyPressed
        if ((evt.getKeyCode() == KeyEvent.VK_ENTER)) {
            txtDni.requestFocus();
        }
    }//GEN-LAST:event_txtNombresKeyPressed

    private void txtApellidoPaternoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtApellidoPaternoKeyPressed
        if (evt.getKeyCode() == evt.VK_ENTER) {
            txtApellidoMaterno.requestFocus();
        }
    }//GEN-LAST:event_txtApellidoPaternoKeyPressed
    
    private void txtDniKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDniKeyPressed
        if (evt.getKeyCode() == evt.VK_ENTER) {
            txtDireccion.requestFocus();
        }
    }//GEN-LAST:event_txtDniKeyPressed

    private void txtDireccionKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDireccionKeyPressed
        if (evt.getKeyCode() == evt.VK_ENTER) {
            txtTel.requestFocus();
        }
    }//GEN-LAST:event_txtDireccionKeyPressed

    private void txtTelKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtTelKeyPressed
        if (evt.getKeyCode() == evt.VK_ENTER) {
            if (validar.validarNro(txtTel.getText())) {
                txtCelular.requestFocus();
            } else {
                JOptionPane.showMessageDialog(this, "El teléfono sólo debe contener numeros", "Error", JOptionPane.ERROR_MESSAGE);
                txtTel.requestFocus();
                txtTel.selectAll();
                
            }
        }
    }//GEN-LAST:event_txtTelKeyPressed

    private void txtEmailKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtEmailKeyPressed
        if (evt.getKeyCode() == evt.VK_ENTER) {         
                txtOcupacion.requestFocus();           
        }
    }//GEN-LAST:event_txtEmailKeyPressed

    private void txtCelularKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCelularKeyPressed
        if (evt.getKeyCode() == evt.VK_ENTER) {           
                txtEmail.requestFocus();            
        }
    }//GEN-LAST:event_txtCelularKeyPressed

    private void btnEliminarFotoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminarFotoActionPerformed
        cargarFotoDefecto();
    }//GEN-LAST:event_btnEliminarFotoActionPerformed

    private void txtNacionalidadKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNacionalidadKeyPressed
        if (evt.getKeyCode() == evt.VK_ENTER) {
            if (validar.validarTexto(txtNacionalidad.getText())) {
                txtRecomendado.requestFocus();
            } else {
                JOptionPane.showMessageDialog(this, "La nacionalidad no debe contener numeros/símbolos", "Error", JOptionPane.ERROR_MESSAGE);
                txtNacionalidad.requestFocus();
                txtNacionalidad.selectAll();
            }
        }
    }//GEN-LAST:event_txtNacionalidadKeyPressed

    private void txtEdadKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtEdadKeyPressed
    }//GEN-LAST:event_txtEdadKeyPressed

    private void txtOcupacionKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtOcupacionKeyPressed
        if (evt.getKeyCode() == evt.VK_ENTER) {
            txtNacionalidad.requestFocus();
        }
    }//GEN-LAST:event_txtOcupacionKeyPressed

private void comboFechaOnSelectionChange(datechooser.events.SelectionChangedEvent evt) {//GEN-FIRST:event_comboFechaOnSelectionChange
    int edad = validar.calcularEdad(comboFecha.getText());
    txtEdad.setText(""+edad);   
}//GEN-LAST:event_comboFechaOnSelectionChange

private void txtAntecedentesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtAntecedentesMouseClicked
// TODO add your handling code here:
    txtAntecedentes.selectAll();
}//GEN-LAST:event_txtAntecedentesMouseClicked

private void comboDeptoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_comboDeptoItemStateChanged
    comboProvincia.removeAllItems();
    int cod = comboDepto.getSelectedIndex();
    cargarComboProvincias(cod);
}//GEN-LAST:event_comboDeptoItemStateChanged

private void comboProvinciaItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_comboProvinciaItemStateChanged
    comboDistrito.removeAllItems();
    int codD = comboDepto.getSelectedIndex();
    int codP = comboProvincia.getSelectedIndex();
    cargarComboDistritos(codD, codP);
}//GEN-LAST:event_comboProvinciaItemStateChanged

    private void txtRecomendadoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtRecomendadoKeyPressed

        if (evt.getKeyCode() == evt.VK_ENTER) {
            txtAntecedentes.requestFocus();
            txtAntecedentes.selectAll();
        }
    }//GEN-LAST:event_txtRecomendadoKeyPressed

    private void txtApellidoMaternoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtApellidoMaternoKeyPressed
       if ((evt.getKeyCode() == KeyEvent.VK_ENTER)) {
            txtNombres.requestFocus();
        }
    }//GEN-LAST:event_txtApellidoMaternoKeyPressed

    public final void valoresPorDefecto() {
        rbtMasculino.setSelected(true);
        rbtAdulto.setSelected(true);
        txtApellidoPaterno.requestFocus();
        fechaingreso = validar.cambiarFormatoFechaParaBD(comboFecha.getText()); // modificar sino se trabaja con usp
        txtAntecedentes.setText("Sin particularidades.");
    }


    /*
     * Método que carga por defecto una cruz , indicando que no hay foto cargada
     * para el paciente
     */
    public final void cargarFotoDefecto() {
        rutaOrigen = "NoFoto";
        ImageIcon imagenes = new ImageIcon();
        imagenes = new ImageIcon(getClass().getResource("/Media/nofoto2.jpg"));
        Icon icono = new ImageIcon(imagenes.getImage().getScaledInstance(lblFoto.getWidth(), lblFoto.getHeight(), Image.SCALE_DEFAULT));
        lblFoto.setIcon(icono);
    }

    public boolean camposObligatorios() {
        //boolean registrar=true;

        if (validar.esVacio(txtNombres.getText().trim())) {
            JOptionPane.showMessageDialog(this, "Debe ingresar un nombre", "Campo obligatorio", JOptionPane.ERROR_MESSAGE);
            txtNombres.setText("");
            txtNombres.requestFocus();
            return false;
        } else if (!validar.validarTexto(txtNombres.getText())) {
            JOptionPane.showMessageDialog(this, "El nombre no debe contener numeros/símbolos", "Error", JOptionPane.ERROR_MESSAGE);
            txtNombres.requestFocus();
            txtNombres.selectAll();
            return false;
        }

        if (validar.esVacio(txtApellidoPaterno.getText().trim())) {
            JOptionPane.showMessageDialog(this, "Debe ingresar apellidos", "Campo obligatorio", JOptionPane.ERROR_MESSAGE);
            txtApellidoPaterno.setText("");
            txtApellidoPaterno.requestFocus();
            return false;
        } else if (!validar.validarTexto(txtApellidoPaterno.getText())) {
            JOptionPane.showMessageDialog(this, "El apellido no debe contener numeros/símbolos", "Error", JOptionPane.ERROR_MESSAGE);
            txtApellidoPaterno.requestFocus();
            txtApellidoPaterno.selectAll();
            return false;
        }
        
        if (validar.esVacio(txtApellidoMaterno.getText().trim())) {
            JOptionPane.showMessageDialog(this, "Debe ingresar apellidos", "Campo obligatorio", JOptionPane.ERROR_MESSAGE);
            txtApellidoMaterno.setText("");
            txtApellidoMaterno.requestFocus();
            return false;
        } else if (!validar.validarTexto(txtApellidoMaterno.getText())) {
            JOptionPane.showMessageDialog(this, "El apellido no debe contener numeros/símbolos", "Error", JOptionPane.ERROR_MESSAGE);
            txtApellidoMaterno.requestFocus();
            txtApellidoMaterno.selectAll();
            return false;
        }

        if (validar.esVacio(txtAntecedentes.getText().trim())) {
            JOptionPane.showMessageDialog(this, "Debe ingresar Antecedentes", "Campo obligatorio", JOptionPane.ERROR_MESSAGE);
            txtAntecedentes.setText(""); 
            txtAntecedentes.requestFocus();
            return false;
        }
        //Si el campo esta vacio salta el primer if - Si el Dni es incorrecto salta el else if    
        if (validar.esVacio(txtDni.getText())) {
            JOptionPane.showMessageDialog(this, "Debe ingresar DNI", "Campo obligatorio", JOptionPane.ERROR_MESSAGE);
            txtDni.requestFocus();
            return false;
        } else if (!validar.validarDni(txtDni.getText())) {
            JOptionPane.showMessageDialog(this, "DNI incorrecto, sólo debe contener numeros y no debe superar los 8 dígitos", "Error", JOptionPane.ERROR_MESSAGE);
            txtDni.requestFocus();
            txtDni.selectAll();
            return false;
        }        
        
        if (validar.esVacio(txtDireccion.getText().trim())) {
            JOptionPane.showMessageDialog(this, "Debe ingresar Direccion", "Campo obligatorio", JOptionPane.ERROR_MESSAGE);
            txtDireccion.requestFocus();
            return false;
        }
        
        if(!validar.esVacio(txtTel.getText())){                
           if(!validar.validarTelefono(txtTel.getText())) {
            JOptionPane.showMessageDialog(this, "Telefono incorrecto, sólo debe contener numeros y no debe superar los 7 dígitos", "Error", JOptionPane.ERROR_MESSAGE);
            txtTel.requestFocus();
            txtTel.selectAll();
            return false;
        }}
        
        if(!validar.esVacio(txtCelular.getText())){                
           if(!validar.validarCelular(txtCelular.getText())) {
            JOptionPane.showMessageDialog(this, "Celular incorrecto, sólo debe contener numeros y no debe superar los 9 dígitos", "Error", JOptionPane.ERROR_MESSAGE);
            txtCelular.requestFocus();
            txtCelular.selectAll();
            return false;
        }}
        
        if (validar.esVacio(txtEmail.getText())) {
            JOptionPane.showMessageDialog(this, "Debe ingresar E-mail", " Error", JOptionPane.ERROR_MESSAGE);
            txtEmail.requestFocus();
            return false;
        } else if (!validar.validarEmail(txtEmail.getText())) {
            JOptionPane.showMessageDialog(this, "E-mail incorrecto, ingrese nuevamente", "Error", JOptionPane.ERROR_MESSAGE);
            txtEmail.requestFocus();
            txtEmail.selectAll();
            return false;
        }
        
        
        
        return true;
    }

    /*
     * MÉTODO QUE AUTOINCREMENTA EL CÓDIGO DEL ÚLTIMO DEL PACIENTE REGISTRADO
     */
    public final void cargarCodigo() {
        ControlPaciente control = new ControlPaciente();
        //txtCodigoPaciente.setText(""+validar.agregarCerosYNumeroAIncrementar(control.cargarCodigo(),1));
        txtCodigoPaciente.setText("" + control.cargarCodigo());
    }

    /*
     * LIMPIA LOS DATOS INGRESADOS EN EL FORMULARIO
     */
    public void limpiarVentana() {
        txtNombres.setText("");
        txtApellidoPaterno.setText("");
        txtApellidoMaterno.setText(""); 
        txtDni.setText("");
        txtNacionalidad.setText("");
        txtDireccion.setText("");
        txtTel.setText("");
        txtCelular.setText("");
        txtEdad.setText("");
        txtEmail.setText("");
        txtOcupacion.setText("");
        txtAntecedentes.setText("");
        txtRecomendado.setText("");
        cargarFotoDefecto();
        rbtMasculino.setSelected(true);
        rbtAdulto.setSelected(true);
        txtApellidoPaterno.requestFocus();
        comboFecha.setText(fechaingreso);

    }

    /*
     * CARGA LA FOTO SELECCIONADA POR EL USUARIO
     */
    public void cambiarImagen() {
        JFileChooser jf = new JFileChooser();
        jf.setDialogTitle("Seleccione una foto");
        jf.setAcceptAllFileFilterUsed(false);
        jf.setFileFilter(new FileNameExtensionFilter("jpg, png, gif", "jpg", "png", "gif"));
        int sel = jf.showOpenDialog(null);

        if (sel == JFileChooser.APPROVE_OPTION) {
            rutaOrigen = jf.getSelectedFile().getAbsolutePath();
            this.etiquetaImagen = new ImageIcon(rutaOrigen);
            Icon icono = new ImageIcon(etiquetaImagen.getImage().getScaledInstance(lblFoto.getWidth(), lblFoto.getHeight(), Image.SCALE_DEFAULT));
            lblFoto.setIcon(icono);
        }
    }

    public final void cargarComboDeptos() {
        ControlUbigeo control = new ControlUbigeo();
        ArrayList<ArrayList> listado = control.listarDeptos();

        for (int i = 0; i < listado.size(); i++) {
            comboDepto.addItem(listado.get(i).get(1).toString());
        }
    }

    public void cargarComboProvincias(int cod) {

        ControlUbigeo control = new ControlUbigeo();
        ArrayList<ArrayList> listado = control.listarProvincias(cod + 1);

        for (int i = 0; i < listado.size(); i++) {
            comboProvincia.addItem(listado.get(i).get(0).toString());


        }
    }

    public void cargarComboDistritos(int codDepto, int codProv) {
        ControlUbigeo control = new ControlUbigeo();
        ArrayList<ArrayList> listado = control.listarDistritos(codDepto + 1, codProv + 1);

        for (int i = 0; i < listado.size(); i++) {
            comboDistrito.addItem(listado.get(i).get(0).toString());


        }

    }

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {


                Visual.aspectoMac();
                new frmRegistrarPaciente().setVisible(true);

            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAgregarFoto;
    private javax.swing.JButton btnEliminarFoto;
    private javax.swing.ButtonGroup btnGroupGenero;
    private javax.swing.ButtonGroup btnGroupGrupo;
    private javax.swing.JButton btnRegistrar;
    private javax.swing.JComboBox comboDepto;
    private javax.swing.JComboBox comboDistrito;
    private datechooser.beans.DateChooserCombo comboFecha;
    private javax.swing.JComboBox comboProvincia;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblCodPaciente;
    private javax.swing.JLabel lblFoto;
    private javax.swing.JRadioButton rbtAdulto;
    private javax.swing.JRadioButton rbtFemenino;
    private javax.swing.JRadioButton rbtMasculino;
    private javax.swing.JRadioButton rbtNinho;
    private javax.swing.JTextArea txtAntecedentes;
    private javax.swing.JTextField txtApellidoMaterno;
    private javax.swing.JTextField txtApellidoPaterno;
    private javax.swing.JTextField txtCelular;
    private javax.swing.JTextField txtCodigoPaciente;
    private javax.swing.JTextField txtDireccion;
    private javax.swing.JTextField txtDni;
    private javax.swing.JTextField txtEdad;
    private javax.swing.JTextField txtEmail;
    private javax.swing.JTextField txtNacionalidad;
    private javax.swing.JTextField txtNombres;
    private javax.swing.JTextField txtOcupacion;
    private javax.swing.JTextField txtRecomendado;
    private javax.swing.JTextField txtTel;
    // End of variables declaration//GEN-END:variables
}
